﻿$(function () {
    //统计 上架总数 总和
    var TotalAdvertValue = 0;
    $('td[id^=TotalAdvert_]').each(function () {
        TotalAdvertValue += parseInt($(this).text());
    });
    var PutOnAdvertValue = 0;
    $('td[id^=PutOnAdvert_]').each(function () {
        PutOnAdvertValue += parseInt($(this).text());
    });
    var PullOfAdvertValue = 0;
    $('td[id^=PullOfAdvert_]').each(function () {
        PullOfAdvertValue += parseInt($(this).text());
    });
    //var RefreshAdvertValue = 0;
    //$('td[id^=RefreshAdvert_]').each(function () {
    //    RefreshAdvertValue += parseInt($(this).text());
    //});
    var CloneAnjkValue = 0;
    $('td[id^=CloneAnjk_]').each(function () {
        CloneAnjkValue += parseInt($(this).text());
    });
    var Clone58Value = 0;
    $('td[id^=Clone58_]').each(function () {
        Clone58Value += parseInt($(this).text());
    });
    var CloneTaoBaoValue = 0;
    $('td[id^=CloneTaoBao_]').each(function () {
        CloneTaoBaoValue += parseInt($(this).text());
    });
    //var CloneSinaValue = 0;
    //$('td[id^=CloneSina_]').each(function () {
    //    CloneSinaValue += parseInt($(this).text());
    //});
    //var CloneSoFunValue = 0;
    //$('td[id^=CloneSoFun_]').each(function () {
    //    CloneSoFunValue += parseInt($(this).text());
    //});
    //var tdvalue = "<tr><td>总计</td><td>" + TotalAdvertValue + "</td><td>" + PutOnAdvertValue + "</td><td>" + PullOfAdvertValue + "</td><td>" + RefreshAdvertValue + "</td><td>" + CloneAnjkValue + "</td><td>" + Clone58Value + "</td><td>" + CloneSinaValue + "</td><td>" + CloneSoFunValue + "</td></tr>";
    //var tdvalue = "<tr><td>总计</td><td>" + TotalAdvertValue + "</td><td>" + PutOnAdvertValue + "</td><td>" + PullOfAdvertValue + "</td><td>" + CloneAnjkValue + "</td><td>" + Clone58Value + "</td><td>" + CloneTaoBaoValue + "</td></tr>";
    var tdvalue = "<tr><td>总计</td><td>" + TotalAdvertValue + "</td><td>" + PutOnAdvertValue + "</td><td>" + PullOfAdvertValue + "</td><td>" + CloneAnjkValue + "</td></tr>";
    $("#tbDayCount tbody").append(tdvalue);


    //智能提示Start
    EmployeePrompt.getDepartAndEmployeeByInput('txtDeptName', 'hidDeptId', 'txtUserName', 'hidUserId', false, 'private', 1, '请输入员工姓名', '请输入部门名称', true);
    //智能提示End


    $("#btnSearch").unbind("click");
    $("#btnSearch").click(function () {

        $("#imgLoading").show();
        var reqData = {
            'DeptKeyId': $("#hidDeptId").val(),
            'UserKeyId': $("#hidUserId").val(),
            'StartTime': $("#txtStartTime").val(),
            'EndTime': $("#txtEndTime").val(),
            'CountType': $("#selCountType").val()
        };
        $.AjaxAgency('/advert/AdvertMoreCount', reqData, function (data) {
            if (data) {
                $("#tbMoreCount tr").remove();
                var json = $.parseJSON(data);
                var arr_key = new Array();
                arr_key.push("<tr>");
                $.each(json[0], function (i) {
                    arr_key.push("<th>");
                    arr_key.push(i);
                    arr_key.push("</th>");
                });
                arr_key.push("<th>");
                arr_key.push("总计");
                arr_key.push("</th>");
                arr_key.push("</tr>");
                $("#tbMoreCount").append(arr_key.join(""));
                var arr_value = new Array();
                $.each(json, function (i) {
                    arr_value.push("<tr>");
                    $.each(json[i], function (j) {
                        arr_value.push("<td>");
                        arr_value.push(json[i][j]);
                        arr_value.push("</td>");
                    });
                    arr_value.push("<td>");
                    var totalvalue = 0;
                    $.each(json[i], function (j) {
                        if (j != "日期") {
                            totalvalue += parseInt(json[i][j]);
                        }
                    });
                    arr_value.push(totalvalue);
                    arr_value.push("</td>");
                    arr_value.push("</tr>");
                });
                $("#tbMoreCount").append(arr_value.join(""));
            }
            else {
                $("#tbMoreCount tr").remove();
                $.OKDialogAgency('<div class="tc">没有请求数据！</div>');
            }
            $("#imgLoading").hide();
        });
    });

    //浮动的工具栏 yjj添加
    var state1 = true; //存储顶部显示的状态
    $(window).scroll(function () {
        if ($(window).scrollTop() > 80) {
            if (state1) {
                //执行浮动层出现后的代码
                $(".fixed-div").show();
            }
            state1 = false;
        } else {
            if (!state1) {
                //执行浮动层出现前的代码
                $(".fixed-div").hide();
            }
            state1 = true;
        }
    });
    $(".fixed-div").css("top", "0");
    var n = $("#tbDayCount th:visible").size();
    for (var i = 0; i < n; i++) {
        $(".fixed-div div").append("<span class='fixed-span'></span>");
        $(".fixed-div div").find(".fixed-span").eq(i).html($("#tbDayCount th:visible").eq(i).html());
        $(".fixed-div div").find(".fixed-span").eq(i).css({ "width": $("#tbDayCount th:visible").eq(i).outerWidth(), "text-align": "center" });
    }

});